<template>
  <div style="display: inline">
    <el-button @click="editShow" type="info"  class="mgr10 mgb10">修改1688订单号</el-button>
    <el-dialog title="修改1688订单号" :visible.sync="dialog">
      <el-form :model="currentForm" label-width="150px" :rules="rules" ref="currentForm">
        <el-form-item label="订单号" prop="order1688">
          <el-input
            v-model.trim="currentForm.order1688"
            maxlength="19"
            show-word-limit
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="deleteRow">删 除</el-button>
        <el-button type="primary" @click="submitForm" :disabled="isChange()">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import {deepCopy} from "@/utils";
import {deleteStickerOrder, deliveryOrder, editDelivery, editOrder1688, getExpressList, ignoreOrder} from "@/api/order";
import expressCompanyMixin from "@/views/order/mixin/expressCompany";

export default {
  name: "EditOrder1688Button",
  mixins: [expressCompanyMixin],
  props:{
    orderId:{
      type: String,
      required: true,
    },
    order1688:{
      type: String,
      required: true,
    },
    disable:{
      default: false,
    }
  },
  computed:{

  },
  created() {
    // this.getOptions()
    this.currentForm.orderId = this.orderId;
    this.currentForm.order1688 = this.order1688;
  },
  data(){
    return {
      dialog : false,
      loading: false,
      currentForm:{
        orderId: '', // 订单号
        order1688: '', // 1688订单号
      },
      options: [],
      rules:{
        order1688:[
          { required: true, message: '请填写1688订单号', trigger: 'blur' },
          { pattern: /^[0-9]+$/, message: '1688订单号格式有误'},
        ],
      }
    };
  },
  methods:{
    editShow(){
      this.dialog = true
    },
    submitForm(){
      this.$refs.currentForm.validate(valid =>{
        if(valid){
          this.$confirm('', '确认修改当前1688订单号？', {
            dangerouslyUseHTMLString: true,
            confirmButtonText: '确定',
            cancelButtonClass: '取消'
          })
            .then(res=>{
              // 点击了确定

              this.loading = true
              const postData = deepCopy(this.currentForm)
              editOrder1688(postData)
                .then(res=>{
                  if(res.error === 0){
                    this.$successMessage(res.message)
                    this.dialog = false
                    this.$emit('changeOrder',true)
                  }else{
                    this.$errorMessage(res.message)
                  }
                })
            })
            .catch(res=>{
              // 点击了取消
            });
        }
      })
    },
    // 删除快递单
    deleteRow(){
      this.$confirm('删除后订单将重新变为未处理状态，请重新处理', '确认删除当前1688订单号？', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确定',
        cancelButtonClass: '取消'
      })
        .then(res=>{
          // 点击了确定
          deleteStickerOrder(this.orderId)
            .then(res=>{
              if(res.error === 0){
                this.$successMessage(res.message)
                this.dialog = false
                this.$emit('changeOrder',true)
              }else{
                this.$errorMessage(res.message)
              }
            })
        })
        .catch(res=>{
          // 点击了取消
        });
    },
    // 判断是否有改变数据
    isChange(){
      return this.order1688 == this.currentForm.order1688
    }
  }
}
</script>

<style scoped>

</style>
